import _ from 'lodash';
/**
 * 对后端返回的错误信息处理正则
 */
const ERROR_MESSAGES_RE = [
  { re: /^.*(duplicate key){1}.*(username){1}.*$/, message: '用户名重复' },
  { re: /max login times error/, message: '用户被锁定' },
  { re: /user expired error/, message: '用户帐号已失效' },
  { re: /exceed max site number/, message: '可添加资产数已达上限' },
  { re: /exceed max user number/, message: '可添加用户已达上限' },
  { re: /^.*(duplicate key){1}.*(tasks){1}.*(name){1}.*$/, message: '任务名重复' },
  { re: /^.*(duplicate key){1}.*(sites){1}.*(ipUrl){1}.*$/, message: '已有相同资产，请勿重复添加' },
  {
    re: /^username size limit: (\d*),password size limit: (\d*)/,
    message: matchs => {
      let usernameSizeLimit = _.get(matchs, '1', 0) / 1024;
      let passwordSizeLimit = _.get(matchs, '2', 0) / 1024;
      if (usernameSizeLimit === passwordSizeLimit) {
        return `请确保您上传的文件小于${passwordSizeLimit}kb`;
      }
    }
  },
  { re: /^(username|password) minimum size is 1/, message: '请确保您上传的字典文件不为空' },
  {
    re: /^demonstrate forbidden$/,
    message: 'demonstrate forbidden'
  },
  {
    re: /^exist running or waiting full web scan task$/,
    message: '当前有全量资产的Web指纹探测任务正在执行或等待，请勿重复下发'
  },
  {
    re: /^be-error:(.*)/,
    message: matchs => _.trim(_.get(matchs, 1, ''))
  },
  // 临时解决中文报错问题
  {
    re: /^资产超出证书限制数量$/,
    message: '资产超出证书限制数量'
  }
];
export default ERROR_MESSAGES_RE;
